package com.exercises;

import com.exercises.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Exercise897 {
    List<TreeNode> list = new ArrayList<>();

    public TreeNode increasingBST(TreeNode root) {
        scan(root);
        for (TreeNode t : list) {
            System.out.println(t.val);

        }

        TreeNode first = list.get(0);
        for (int i = 1; i < list.size(); i++) {
            first.left = null;
            first.right = list.get(i);
            first = list.get(i);
        }
        first.left = null;
        return list.get(0);

    }

    public void scan(TreeNode root) {
        if (root == null) {
            return;
        }
        scan(root.left);
        list.add(root);
        scan(root.right);
    }
}
